/*!
 * \file t__split_eq_string.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2017/03/07
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frjson_checker.h"
#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void case1(void)
{
    unsigned char *p_data_in = NULL;
    unsigned int ui_data_len = 0;
    int i_ret = 0;
    
    i_ret = frjson_format_detect(p_data_in, ui_data_len);
    
    CU_ASSERT_EQUAL(i_ret, FR_NO);

    return;

}

static void case2(void)
{
    unsigned char *p_data_in = NULL;
    unsigned int ui_data_len = 0;
    int i_ret = 0;

    p_data_in = (unsigned char *) frstrdup((char *)"[1,\"sayHello\",1,1,{\"1\":{\"map\":[\"i16\",\"i64\",2,{\"1\":2,\"3\":4}]}}]");
    ui_data_len = strlen((char *)"[1,\"sayHello\",1,1,{\"1\":{\"map\":[\"i16\",\"i64\",2,{\"1\":2,\"3\":4}]}}]");

    i_ret = frjson_format_detect(p_data_in, ui_data_len);

    CU_ASSERT_EQUAL(i_ret, FR_YES);
    frfree(p_data_in);

    return;

}


static void case3(void)
{
    unsigned char *p_data_in = NULL;
    unsigned int ui_data_len = 0;
    int i_ret = 0;

    p_data_in = (unsigned char *) frstrdup((char *)"{\"1\":2,\"3\":4}");
    ui_data_len = strlen((char *)"{\"1\":2,\"3\":4}");

    i_ret = frjson_format_detect(p_data_in, ui_data_len);

    CU_ASSERT_EQUAL(i_ret, FR_YES);
    frfree(p_data_in);

    return;

}


static void case4(void)
{
    unsigned char *p_data_in = NULL;
    unsigned int ui_data_len = 0;
    int i_ret = 0;

    p_data_in = (unsigned char *) frstrdup((char *)"[\"1\":2,\"3\":4}");
    ui_data_len = strlen((char *)"[\"1\":2,\"3\":4}");

    i_ret = frjson_format_detect(p_data_in, ui_data_len);

    CU_ASSERT_EQUAL(i_ret, FR_NO);
    frfree(p_data_in);

    return;

}

int add_suite_frjson_format_detect(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frjson_format_detect()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", case1);
    CU_add_test(pSuite, "case2", case2);
    CU_add_test(pSuite, "case3", case3);
    CU_add_test(pSuite, "case4", case4);

    return FR_SUCC;
}
